<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="身份证号" prop="personId">
        <el-input
          v-model="queryParams.personId"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管控时间" prop="controlLimitTime">
        <el-date-picker clearable
          v-model="queryParams.controlLimitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择管控时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="症状" prop="symptom">
        <el-input
          v-model="queryParams.symptom"
          placeholder="请输入症状"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item  label="核酸检测单号" prop="checkId">
        <el-input
          v-model="queryParams.checkId"
          placeholder="请输入核酸检测单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['eim:diagnostic_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="diagnostic_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"  align="center" />
      <el-table-column label="序号" align="center" width="55" prop="id" />
      <el-table-column label="姓名" align="center" prop="person.name" />
      <el-table-column label="身份证号" align="center" width="200" prop="personId" />
      <el-table-column label="要求管控时间" align="center" prop="controlLimitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.controlLimitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="症状" align="center" prop="symptom" />
      <el-table-column label="核酸检测单号" align="center" prop="checkId" />
      <el-table-column label="采集时间" align="center" prop="eimDataNucleicAcidCheck.acquisitionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eimDataNucleicAcidCheck.acquisitionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-position"
            @click="handleQueryStayPoints(scope.row)"
            v-hasPermi="['eim:diagnostic_info:edit']"
          >查看轨迹</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改确诊信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身份证号" prop="personId">
          <el-input v-model="form.personId" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="要求管控时间" prop="controlLimitTime">
          <el-date-picker clearable
            v-model="form.controlLimitTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择要求管控时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="症状" prop="symptom">
          <el-input v-model="form.symptom" placeholder="请输入症状" />
        </el-form-item>
        <el-form-item label="关联阳性核酸检测单id" prop="checkId">
          <el-input v-model="form.checkId" placeholder="请输入关联阳性核酸检测单id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看行程轨迹对话框 -->
    <el-dialog title="15日内行程记录" :visible.sync="ifShowStayPoints" :before-close="handleClear" width="1600px" append-to-body>
      <el-container style="height: 800px; border: 1px solid #eee">
      <el-aside width="450px" style="background-color: rgb(238, 241, 246)">

        <el-card  class="box-card" v-for="sp in staypointList">
          <div slot="header" class="clearfix">
            <i class="el-icon-position"></i><span>{{sp.startTime}}</span>
            <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
          </div>

          <el-link
            size="mini"
            icon="el-icon-edit"
            @click="selectCard(sp.longitude,sp.latitude)"
            v-hasPermi="['eim:diagnostic_info:edit']"
          >{{sp.address}}</el-link>

        </el-card>


      </el-aside>


      <el-main>
        <testmap style="width: 100%;height: 100%"></testmap>
      </el-main>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      </el-container>
    </el-dialog>

  </div>
</template>


<style>


.el-aside {
  color: #333;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 380px;
}
</style>

<script>
import { listDiagnostic_info, getDiagnostic_info, delDiagnostic_info, addDiagnostic_info, updateDiagnostic_info } from "@/api/eim/diagnostic_info";
import { getStaypointByPersonId} from "@/api/eim/staypoint";
import testmap from "./map"
export default {
  name: "Diagnostic_info",
  components:{
        testmap
  },
  data() {
    return {


      nowPoint:{
        lng:-1,
        lat:-1
      },
      map: null, // 地图对象

      ifShowStayPoints:false,

      staypointList:[],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 确诊信息表格数据
      diagnostic_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        personId: null,
        controlLimitTime: null,
        symptom: null,
        checkId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        personId: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {

    this.$store.commit('nowPoint',this.nowPoint);
  },
  methods: {

    selectCard(lng,lat){
      this.nowPoint.lng=lng;
      this.nowPoint.lat = lat;
    },

    /** 查询确诊信息列表 */
    getList() {
      this.loading = true;
      listDiagnostic_info(this.queryParams).then(response => {
        this.diagnostic_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        personId: null,
        controlLimitTime: null,
        symptom: null,
        checkId: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加确诊信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDiagnostic_info(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改确诊信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDiagnostic_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDiagnostic_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除确诊信息编号为"' + ids + '"的数据项？').then(function() {
        return delDiagnostic_info(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('eim/diagnostic_info/export', {
        ...this.queryParams
      }, `diagnostic_info_${new Date().getTime()}.xlsx`)
    },
    //查询轨迹按钮
    handleQueryStayPoints(e){


      getStaypointByPersonId(e.personId).then(re=>{
        this.staypointList = re.data;
        console.log(this.staypointList)
        this.$store.commit('SET_SPLIST',this.staypointList);
        this.ifShowStayPoints  =true;
      });


    },
    handleClear(){
      this.nowPoint.lng = -1;
      this.nowPoint.lat = -1;
    }


  }
};
</script>
